/*
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License");  you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * http//www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 *
 * The Original Code is ART Ontology API (Sesame2 Implementation).
 *
 * The Initial Developer of the Original Code is University of Roma Tor Vergata.
 * Portions created by University of Roma Tor Vergata are Copyright (C) 2007.
 * All Rights Reserved.
 *
 * ART Ontology API (Sesame2 Implementation) was developed by the Artificial Intelligence Research Group
 * (art.uniroma2.it) at the University of Roma Tor Vergata
 * Current information about the ART Ontology API (Sesame2 Implementation) can be obtained at 
 * http//art.uniroma2.it/owlart
 *
 */
package it.uniroma2.art.owlart.sesame2impl;

import it.uniroma2.art.owlart.model.ARTBNode;
import it.uniroma2.art.owlart.model.ARTLiteral;
import it.uniroma2.art.owlart.model.ARTNode;
import it.uniroma2.art.owlart.model.ARTResource;
import it.uniroma2.art.owlart.model.ARTStatement;
import it.uniroma2.art.owlart.model.ARTURIResource;
import it.uniroma2.art.owlart.model.NodeFilters;
import it.uniroma2.art.owlart.sesame2impl.model.ARTBNodeSesame2Impl;
import it.uniroma2.art.owlart.sesame2impl.model.ARTLiteralSesame2Impl;
import it.uniroma2.art.owlart.sesame2impl.model.ARTNodeSesame2Impl;
import it.uniroma2.art.owlart.sesame2impl.model.ARTResourceSesame2Impl;
import it.uniroma2.art.owlart.sesame2impl.model.ARTStatementSesame2Impl;
import it.uniroma2.art.owlart.sesame2impl.model.ARTURIResourceSesame2Impl;

import org.openrdf.model.BNode;
import org.openrdf.model.Literal;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.URI;
import org.openrdf.model.Value;

/**
 * this class provides convenience methods for bidirectional conversion of Sesame2 RDF types and OWL ART RDF
 * types
 * 
 * @author Armando Stellato
 * 
 */
public class Sesame2ARTResourceFactory {

	/**
	 * converts an OWL ART {@link ARTStatement} to a Sesame 2 {@link Statement}
	 * 
	 * @param artStat
	 * @return
	 */
	static public Statement aRTStatement2SesameStatement(ARTStatement artStat) {
		if (artStat == null)
			return null;
		return ((ARTStatementSesame2Impl) artStat).getSesameStatement();
	}

	/**
	 * converts Sesame2 {@link Statement} to an OWL ART {@link ARTStatement}
	 * 
	 * @param stat
	 * @return
	 */
	static public ARTStatement sesameStatement2ARTStatement(Statement stat) {
		if (stat == null)
			return null;
		return new ARTStatementSesame2Impl(stat);
	}

	/**
	 * converts an OWL ART {@link ARTURIResource} to a Sesame2 {@link URI}
	 * 
	 * @param sTres
	 * @return
	 */
	static public URI aRTURIResource2SesameURI(ARTURIResource sTres) {
		if (sTres == null)
			return null;
		if (sTres == NodeFilters.ANY)
			return null;
		return ((ARTURIResourceSesame2Impl) sTres).getSesameURI();
	}

	/**
	 * converts an OWL ART {@link ARTResource} to a Sesame2 {@link Resource}
	 * 
	 * @param sTres
	 * @return
	 */
	static public Resource aRTResource2SesameResource(ARTResource sTres) {
		if (sTres == null)
			return null;
		if (sTres == NodeFilters.ANY)
			return null;
		return ((ARTResourceSesame2Impl) sTres).getSesameResource();
	}

	/**
	 * converts an OWL ART {@link ARTNode} to a Sesame2 {@link Value}
	 * 
	 * @param sTNode
	 * @return
	 */
	static public Value aRTNode2SesameValue(ARTNode sTNode) {
		if (sTNode == null)
			return null;
		if (sTNode == NodeFilters.ANY)
			return null;
		else
			return ((ARTNodeSesame2Impl) sTNode).getSesameValue();
	}

	/**
	 * converts an OWL ART {@link ARTLiteral} to a Sesame2 {@link Literal}
	 * 
	 * @param stLiteral
	 * @return
	 */
	static public Literal aRTLiteral2SesameLiteral(ARTLiteral stLiteral) {
		if (stLiteral == null)
			return null;
		if (stLiteral == NodeFilters.ANY)
			return null;
		else
			return ((ARTLiteralSesame2Impl) stLiteral).getLiteral();
	}

	/**
	 * converts a Sesame2 {@link Resource} to an OWL ART {@link ARTResource}
	 * 
	 * @param res
	 * @return
	 */
	static public ARTResource sesameResource2ARTResource(Resource res) {
		if (res == null)
			return NodeFilters.ANY;
		else
			return new ARTResourceSesame2Impl(res);
	}

	/**
	 * converts a Sesame2 {@link URI} to an OWL ART {@link ARTURIResource}
	 * 
	 * @param res
	 * @return
	 */
	static public ARTURIResource sesameURI2ARTURIResource(URI res) {
		if (res == null)
			return NodeFilters.ANY;
		else
			return new ARTURIResourceSesame2Impl(res);
	}

	/**
	 * converts a Sesame2 {@link Value} to an OWL ART {@link ARTNode}
	 * 
	 * @param val
	 * @return
	 */
	static public ARTNode sesameValue2ARTNode(Value val) {
		if (val == null)
			return NodeFilters.ANY;
		else
			return new ARTNodeSesame2Impl(val);
	}

	/**
	 * converts a Sesame2 {@link Literal} to an OWL ART {@link ARTLiteral}
	 * 
	 * @param sesLiteral
	 * @return
	 */
	static public ARTLiteral sesameLiteral2ARTLiteral(Literal sesLiteral) {
		if (sesLiteral == null)
			return NodeFilters.ANY;
		else
			return new ARTLiteralSesame2Impl(sesLiteral);
	}

	/**
	 * converts a Sesame2 {@link BNode} to an OWL ART {@link ARTBNode}
	 * 
	 * @param sesBNode
	 * @return
	 */
	static public ARTBNode sesameBNode2ARTBNode(BNode sesBNode) {
		if (sesBNode == null)
			return NodeFilters.ANY;
		else
			return new ARTBNodeSesame2Impl(sesBNode);
	}

}
